package com.wandian.ui.skins
{
	import flash.display.Graphics;	

	import com.wandian.utils.ColorUtil;
	import com.wandian.utils.Const;

	public class ScrollArrowSkin extends Skin
	{
		public function ScrollArrowSkin()
		{
			super();
		}

		override public function updateDisplay(w:int, h:int,state:String,...args):void
		{
			var isUp:Boolean=this.styleClient.name == "upArrow"
			var borderColor:int=getStyle("borderColor");
			var borderDarkColor:int=ColorUtil.adjustBrightness(borderColor, -50)

			var borderColors:Array=isUp ? [borderColor, borderDarkColor] : [borderDarkColor, ColorUtil.adjustBrightness(borderColor, -50)]
			var fillAlphas:Array=getStyle("fillAlphas");
			var fillColors:Array=getStyle("fillColors");
			var highlightAlphas:Array=getStyle("highlightAlphas");
			var themeColor:int=getStyle("themeColor");
			var themeDarkColor:int=ColorUtil.adjustBrightness(themeColor, -25);
			var arrowColor:int=getStyle("arrowColor");
			var g:Graphics=this.graphics
			g.clear();

			var width:int=w;
			var height:int=h;

			switch (state)
			{

				case "over":
				{
					var overFillColors:Array=[fillColors[2], fillColors[3]];
					var overFillAlphas:Array=[fillAlphas[2], fillAlphas[3]];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 0, 0)
					g.beginGradientFill("linear", [themeColor, themeDarkColor], Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRect(0, 0, w, h)
					w-=2
					h-=2
					g.drawRect(1, 1, w, h)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", overFillColors, overFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					break;
				}
				case "down":
				{
					var downFillColors:Array=[ColorUtil.adjustBrightness(themeColor, 85), ColorUtil.adjustBrightness(themeColor, 60)];

					//border
					g.beginFill(themeColor, 1)
					g.drawRect(0, 0, w, h)
					w-=2
					h-=2
					g.drawRect(1, 1, w, h)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", downFillColors, Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					break;
				}

				default:
				{
					var upFillColors:Array=[fillColors[0], fillColors[1]];
					var upFillAlphas:Array=[fillAlphas[0], fillAlphas[1]];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 0, 0)
					g.beginGradientFill("linear", borderColors, Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRect(0, 0, w, h)
					w-=2
					h-=2
					g.drawRect(1, 1, w, h)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", upFillColors, upFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					break
				}

			}
			g.beginFill(arrowColor);
			if (isUp)
			{
				g.moveTo(width / 2, 6);
				g.lineTo(width - 5, height - 6);
				g.lineTo(5, height - 6);
				g.lineTo(width / 2, 6);
			}
			else
			{
				g.moveTo(width / 2, height - 6);
				g.lineTo(width - 5, 6);
				g.lineTo(5, 6);
				g.lineTo(width / 2, height - 6);
			}
			g.endFill();
		}

	}
}